﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace TonyNet4V1.Control
{
	
	public class ITemplateLinkButton : ITemplate
	{
		private string strColumnName;
		private DataControlRowType dcrtColumnType;

		public List<LinkButton> listLinkButton;

		public ITemplateLinkButton()
		{
			listLinkButton = new List<LinkButton>();
		}

		public ITemplateLinkButton(DataControlRowType dcrtType)
			: this()
		{
			this.dcrtColumnType = dcrtType;
		}

		public ITemplateLinkButton(string strColumnName, DataControlRowType dcrtType)
			: this()
		{
			this.strColumnName = strColumnName;
			this.dcrtColumnType = dcrtType;
		}

		public void InstantiateIn(System.Web.UI.Control ctlContainer)
		{
			switch (dcrtColumnType)
			{
				case DataControlRowType.Header:

					Literal ltr = new Literal();
					ltr.Text = strColumnName;
					ctlContainer.Controls.Add(ltr);
					break;
				case DataControlRowType.DataRow:

					for (int i = 0; i < listLinkButton.Count; i++)
					{
						LinkButton lBtn = new LinkButton();

						lBtn.CommandName = listLinkButton[i].CommandName;
						lBtn.CommandArgument = listLinkButton[i].CommandArgument;
						lBtn.Text = listLinkButton[i].Text;
						lBtn.OnClientClick = listLinkButton[i].OnClientClick;
						lBtn.ID = listLinkButton[i].ID;
						lBtn.CssClass = listLinkButton[i].CssClass;
						lBtn.Visible = listLinkButton[i].Visible;

						ctlContainer.Controls.Add(lBtn);
					}

					break;

			}
		}

	}
}